Imports System.Windows.Forms
Imports System.Drawing.Printing
Public Class DlgOrder
    Public employeeID As String
    Public Coupon As String
    Public Quantity As Integer
    Public content As String
    Public print As Boolean
    Public LeftCoupon As String
    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Coupon = cbCoupon.SelectedItem.item(0)
        Quantity = nupQuantity.Value
        print = chkPrint.Checked
        LeftCoupon = txtLeft.Text
        If Quantity > 0 Then 'And Convert.ToDouble(txtLeft.Text) >= 0
            Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Else
            Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        End If

        Me.Close()
    End Sub
    
    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub


    Private Sub DlgOrder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        txtEmployeeID.Text = employeeID
        txtFullName.Text = db.getvalue("select * from  Employee_CuChi  where employeeid = '" & employeeID & "'", "eFullname")
        'txtLeft.Text = Math.Round(LeftCoupon(employeeID) - nupQuantity.Value, 2)
        nupQuantity.Value = 1
        chkPrint.Checked = db.getvalue("select * from options_CuChi where oname = 'Print'", "ovalue")
        cbCoupon.DataSource = db.getvalue("select * from Coupon_CuChi ").Tables(0)
        cbCoupon.DisplayMember = "CName"
        cbCoupon.ValueMember = "CouponID"
        cbCoupon.SelectedIndex = FindIndex(cbCoupon, DisplayCoupon, False)
        If cbCoupon.SelectedIndex = -1 Then cbCoupon.SelectedIndex = 0
        nupQuantity_ValueChanged(sender, e)

        Dim b As Byte()
        Try
            If IsDBNull(db.getvalue("select * from  Employee_CuChi  where employeeID ='" & employeeID & "'").Tables(0).Rows(0).Item("epicture")) Then
                pbEmployee.Image = Nothing
                Exit Try
            End If
            b = CType(db.getvalue("select * from  Employee_CuChi  where employeeID ='" & employeeID & "'").Tables(0).Rows(0).Item("epicture"), Byte())
            Dim mem As New System.IO.MemoryStream(b)
            pbEmployee.Image = Image.FromStream(mem)
        Catch ex As Exception
            pbEmployee.Image = Nothing
        End Try
        If FrTransactions._autoOrder = 1 Then
            Me.Visible = False
            OK_Button_Click(sender, e)
        End If
        'If db.getvalue("select * from options where oname = 'Order'", "ovalue") = 1 Then
        '    Me.Visible = False
        '    OK_Button_Click(sender, e)
        'End If


    End Sub

    
    Private Sub nupQuantity_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nupQuantity.ValueChanged
        ' If cbCoupon.Text = "" Then Exit Sub
        On Error Resume Next
        txtLeft.Text = LeftC(employeeID, cbCoupon.SelectedItem.item(0), nupQuantity.Value)
    End Sub
    
  

    Private Sub txtLeft_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtLeft.TextChanged
        If Convert.ToDouble(txtLeft.Text) < 0 Then
            OK_Button.Enabled = False
        Else
            OK_Button.Enabled = True
        End If
    End Sub
End Class
